#!/usr/bin/env python
# -*- coding: utf-8 -*-
import itertools

def reziprok(d,potenz):
    return pow(10,potenz)/d 

def testEqualSeqs(seq1,seq2):
    return seq1==seq2

def cycleLength(cycleStr):
    length=len(cycleStr)
    middle=length/2
    endFirstSeq=middle
    beginFirstSeq=middle
    beginSecondSeq=middle+1
    endSecondSeq=middle+1
    cycleFound=-1
    for idx in range(1,middle):
        firstSeq=cycleStr[beginFirstSeq:endFirstSeq]
        secondSeq=cycleStr[beginSecondSeq:endSecondSeq]        
        if cycleFound<2 and firstSeq==secondSeq:
            cycleFound=idx            
        beginFirstSeq -=1
        endSecondSeq  +=1
    return cycleFound
            
        

maxCylceLength=1
maxCylceAt=0
for d in range(1,1001):
    rezNo=reziprok(d,3000)
    rezStr=str(rezNo)
    if cycleLength(rezStr)>maxCylceLength:
        maxCylceLength=cycleLength(rezStr)
        maxCycleAt=d
    print d, rezStr, cycleLength(rezStr)

print "maxCycle", maxCylceLength, "with", maxCycleAt
 

